﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using MTC.Common.Configuration;
using MTC.Common.DTO;

namespace MTC.DataAccess
{
    public static class ShiftDataAccess
    {
        public static List<Shift> GetShiftTypes()
        {
            List<Shift> listOfShiftType = new List<Shift>();

            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);
            if (db != null)
            {
                const string sqlCommandText = "spShiftType_GetAllShiftTypes";
                using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
                {

                    using (SqlDataReader dataReader = db.ExecuteReader(sqlCommand) as SqlDataReader)
                    {
                        Shift entity;

                        if (dataReader != null)
                            while (dataReader.Read())
                            {
                                entity = new Shift();
                                if (!Convert.IsDBNull(dataReader["ShiftId"]))
                                    entity.ShiftId = Convert.ToInt32(dataReader["ShiftId"]);
                                if (!Convert.IsDBNull(dataReader["ShiftDescription"]))
                                    entity.ShiftDescription = Convert.ToString(dataReader["ShiftDescription"]);

                                listOfShiftType.Add(entity);
                            }
                    }
                }
            }
            return listOfShiftType;
            
 
        }

    
    
    }
}
